

/**
 * 随机生成首页图片
 * @returns {Function}
 */

function backImg(){
    var Image = new Array(10);
    Image[0] = 'http://ww2.sinaimg.cn/bmiddle/005ZWQyIjw1etryw3argij30s30h77ek.jpg';
    Image[1] = 'http://pic.qiantucdn.com/58pic/11/23/74/69U58PICFQJ.jpg';
    Image[2] = 'http://imgbdb2.bendibao.com/bjbdb/20151/7/20151735511316.jpg';
    Image[3] = 'http://upload.northnews.cn/2014/0725/1406282443592.jpg';
    Image[4] = 'http://pic.qiantucdn.com/10/75/95/38bOOOPIC13.jpg';
    Image[5] = 'http://m.tuniucdn.com/filebroker/cdn/olb/07/99/0799abb0105ccb62ea503d65db1c1b61_w755_h0_c0_t0.jpg';
    Image[6] = 'http://images1.tianxun.com/news/2015/09/01/wooden-museum-suzdal-russia.jpg';
    Image[7] = 'http://file30.mafengwo.net/M00/39/BB/wKgBpVU5qdKATgWrAAdJkyjOPp048.groupinfo.w600.jpeg';
    Image[8] = 'http://img1.qunarzz.com/travel/poi/1412/7b/7b23700f0ae366e7cdb.jpg_r_720x400x95_3f51b1fb.jpg';
    Image[9] = 'http://img1.cbi360.net/2015/8/23/201582316814168.jpg';
    Image[10] = 'http://www.guandongphoto.com/data/attachment/forum/201604/23/063523yutf7vtzh9z2w042.jpg';
    Image[11] = 'http://www.cenews.com.cn/ztbd1/gzqghjfx/fengxian_photo/201009/W020100923486838857578.jpg';
    Image[12] = 'http://file28.mafengwo.net/M00/43/39/wKgB6lT-m0mACXMYABAXQSW_Ip460.groupinfo.w600.jpeg';
    Image[13] = 'http://tnf-story.b0.upaiyun.com/2013/07/13742983560683.jpeg%21700x0.jpg';
    Image[14] = 'http://imgbdb3.bendibao.com/weixinbdb/201610/9/2016109111547592.jpg';
    Image[15] = 'http://file28.mafengwo.net/M00/96/E7/wKgB6lR5Yw6ACy9iABpGoHQE60k22.jpeg';
    Image[16] = 'http://attach.bbs.china.com.cn/forum/201411/12/120443kheddolvsvezgqgg.jpg';
    Image[17] = 'http://limg1.qunarzz.com/T1MXZTBXJT1R49Ip6K.jpeg_r_1920x1080x90_da600201.jpeg';
    Image[18] = 'http://www.hyletu.com/images/201606/1465352897434124028.jpg';
    Image[19] = 'http://attach.bbs.china.com.cn/forum/201411/12/120443kheddolvsvezgqgg.jpg';
    Image[20] = 'http://cyjctrip.qiniudn.com/126959/1401423529243p18p5li333fov3s71m9e1ldr17tdp.jpg';

    number = Math.floor(Math.random()*Image.length);
    return function (){
        return Image[number];
    }
}

backImg();


/**
 * URL
 * @type {string}
 */

var URL = "http://101.200.130.104/DotaVideoApi/?r=Youku/GetSokuAllUser&data={q:'travel',pg:1}";
var URL_List = "http://101.200.130.104/DotaVideoApi/?r=Youku/GetSokuList&data={q:'travel',cp:PAGE,od:1,lt:0,limitdate:0}";
var URL_video = 'http://v.youku.com/v_show/id_%3.html?from=s1.8-1-1.2&spm=a2h0k.8191407.0.0';


/**
 * 首页调取列表
 * @constructor
 */
function IndexData(){
    var request = new XMLHttpRequest();
    request.open('GET', URL);
    request.onreadystatechange = function(){
        if(request.readyState == 4 && request.status == 200){
            var DATA = request.responseText;
            var Parse = JSON.parse(DATA);
            var row = Parse.data;
            var arr = [];
            for( i in row ){
                arr.push(row[i]);
            }

            var html = "";
            for( var i=0; i<arr.length; i++ ){
                var Item = arr[i];
                console.log(arr[i]);
                html += '<div class="col-lg-4 col-md-4 col-xs-12 col-sm-12">'
                        + '<div class="EveryCon relative"><a class="relative" href= "list.html?uid='+Item.uid+'" >'
                        + '<div class="EveryBg absolute"></div>'
                        + '<div class="overlay absolute"></div>'
                        + '<div class="EveryName"><div class="EveryNameLeft">' + Item.uname+ '</div></div>'
                        + '</a></div>'
                        + '</div>';
            }

            document.getElementById("categoryEvery").innerHTML = html;
            var Every = document.getElementsByClassName('EveryBg');
            for( var i=0; i< Every.length; i++ ){
                Every[i].style.backgroundImage = "url(" + backImg()() + ")"
            }
        }
    }
    request.send(null);
}



function ListData(page){
    var page = page%1==0 ? page : 1;
    var URL_ListPage = URL_List.replace("PAGE", page);

    var LocationN = location.href;
    var position = LocationN.indexOf("=");
    var UID = LocationN.slice(position+1);
    var URL_Need = URL_List.replace('%3', UID );

    var request = new XMLHttpRequest();
        request.open('GET', URL_ListPage);
        request.onreadystatechange = function(){
            if(request.readyState == 4 && request.status == 200){
                var DATA = request.responseText;
                var row = JSON.parse(DATA);
                var arr = row.data;

                var html = '';

                for( var i=0; i<arr.length; i++ ){
                    var Item = arr[i];

                    var URL_Play = URL_video.replace('%3', Item.vid);

                    html += '<div class="col-lg-4 col-md-4 col-xs-6 col-sm-6">'
                            + '<div class="NodeCon relative">'
                            + '<a href="' + URL_Play + '"><div class="NodeImg relative">'
                            + '<img class="relative" src="'+ Item.pic +'">'
                            + '<div class="absolute click_count">' + Item.click_count + '</div>'
                            + '</div></a>'
                            + '<div class="NodeName">' + Item.name + '</div>'
                            + '<div class="NodeTime relative"><i class="fa fa-play-circle"></i>' + Item.duration + ' <span class="absolute time">' + Item.time + '</span> </div>'
                            + '</div>'
                            + '</div>';

                    //console.log(arr[i])
                }

                var oldhtml = document.getElementById("NodeListEvery").innerHTML;

                document.getElementById('NodeListEvery').innerHTML = oldhtml + html;
            }
        };
        request.send(null);

}





















